package teach.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import teach.aistar.model.entity.*;
import teach.aistar.model.vo.Result;
import teach.aistar.service.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/user")
public class OrdersController {
    @Autowired
    private ICarDetailService iCarDetailService;

    @Autowired

    private ICarBandsService iCarBandsService;


    @Autowired
    private ICarStyleService iCarStyleService;

    @Autowired
    private IOrderService iOrderService;

    @Autowired
    private IOrderDetailsService iOrderDetailsService;

    @Autowired
    private IUserDetailService iUserDetailService;

    //订单显示
    @GetMapping("/order")
    public String sale(HttpServletRequest request, HttpSession session) {
        List<Orders> orders=iOrderService.selectOrderAll();
        List<CarBrands> bands = iCarBandsService.selectAll();
        List<OrdersDetails> ordersDetails=iOrderDetailsService.selectDeatilsAll();
        List<CarStyle> styles = iCarStyleService.findAll();
        List<UserDetail> userDetails=iUserDetailService.selectDetailAll();

        request.setAttribute("ordersDetailsList",ordersDetails);
        request.setAttribute("brandsList", bands);
        request.setAttribute("ordersList",orders);
        request.setAttribute("stylesList",styles);
        request.setAttribute("userDetailsList",userDetails);
        return "jsp/backend/page-list-sale";
    }

    //删除订单
    @GetMapping("/deleteOrder")
    @ResponseBody
    public Result deleteSale(String id) {
        iOrderService.deleteById(Integer.valueOf(id));
        iOrderDetailsService.deleteByOrderId(Integer.valueOf(id));//exception
                return new Result("200");
    }
}
